package com.situ.mall.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.common.util.PageResult;
import com.situ.mall.mapper.CategoryMapper;
import com.situ.mall.pojo.entity.Carousel;
import com.situ.mall.pojo.entity.Category;
import com.situ.mall.pojo.query.CategoryQuery;
import com.situ.mall.pojo.vo.CategoryProductVO;
import com.situ.mall.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements ICategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> listAll() {
        return categoryMapper.listAll();
    }

    @Override
    public List<Category> ByCategoryPatientId(Integer id) {
        return categoryMapper.ByCategoryPatientId(id);
    }

    @Override
    public PageResult selectByPage(CategoryQuery categoryQuery) {
        PageHelper.startPage(categoryQuery.getPage(), categoryQuery.getLimit());
        List<Category> list = categoryMapper.selectByPage(categoryQuery);
        PageInfo pageInfo = new PageInfo(list);
        Integer totalCount = (int) pageInfo.getTotal();
        return PageResult.ok(totalCount, list);
    }

    @Override
    public void addParent(Category category) {
        categoryMapper.insertSelective(category);
    }

    @Override
    public void addChildren(Category category) {
        categoryMapper.insertSelective(category);
    }

    @Override
    public void update(Category category) {
        categoryMapper.updateByPrimaryKeySelective(category);
    }

    @Override
    public Category selectById(Integer id) {
        return categoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer countByParentId(Integer categoryId) {
        return categoryMapper.countByParentId(categoryId);
    }

    @Override
    public void deleteById(Integer id) {
        categoryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Integer countNameByParentId(Category category) {
        return categoryMapper.countNameByParentId(category);
    }

    @Override
    public Integer countName(Category category) {
        return categoryMapper.countName(category);
    }

    @Override
    public List<CategoryProductVO> selectBrandCount() {
        return categoryMapper.selectBrandCount();
    }

}
